import requests
from typing import Optional
import json

cmdData = {
    "lineFormat": 0,
    "leader": "202",
    "data": [
        {
            "uid": "202",
            "action": "takeoff",
            "sparams": {"x":0, "y":0, "z":1.3},
            "dparams": {"x": 0, "y": 0, "z": 2},
            "commandNum": "cmdNum:003:move:1704444270941",
            "timeStamp": "1704444270941s",
            "priority": "1",
            }
            ]
}

taskData = {
    "type": "task",  # 原来单指令-cmd，任务-task
    "taskId": "52",
    "uavList": ["UAV001", "UAV002", "UAV003"],
    "commands": [
    {
        # 正常的执行
        "cmdId": "i1asdf33d",
        "lineFormat": 0, # 0不需要队形  1-箭头 2-直线 3-3D直线 4 菱形
        "leader": "leaderId",
        "data": [
            {
                "uid": "1",
                "action": "move",
                "sparams": {},
                "dparams": {"x": 3, "y": 4, "z": 5},
                "priority": ""
            },
            {
                "uid": "2",
                "action": "takeoff",
                "sparams": {},
                "dparams": {},
                "priority": "1"
            }
        ],
        "condition": "",
        "trigger": "",
        "nextId": 2
    },
    {
        "cmdId": "i2asdf33d",
        "lineFormat": 0,
        "leader": "leaderId",
        "data": [
            {
                "uid": "1",
                "action": "move",
                "sparams": {},
                "dparams": {"x": 3, "y": 4, "z": 5},
                "priority": ""
            },
            {
                "uid": "2",
                "action": "takeoff",
                "sparams": {},
                "dparams": {},
                "priority": "1"
            }
        ],
        "condition": {
            "type": "target detection",
            "True": {"nextId": 3},
            "False": {"nextId": 4}
        },
        "trigger": "",
        "nextId": 3
    },
    {
        # 分叉，nextid为多个值
        "cmdId": "i3asdf33d",
        "lineFormat": 0,
        "leader": "leaderId",
        "data": [
            {
                "uid": "1",
                "action": "move",
                "sparams": {},
                "dparams": {"x": 3, "y": 4, "z": 5},
                "priority": ""
            },
            {
                "uid": "2",
                "action": "takeoff",
                "sparams": {},
                "dparams": {},
                "priority": "1"
            }
        ],
        "condition": "",
        "trigger": "",
        "nextId": [4, 5] #分叉，nextid为多个值
    },
    {
        # 触发条件 如时间/事件
        "cmdId": "i4asdf33d",
        "lineFormat": 0,
        "leader": "leaderId",
        "data": [
            {
                "uid": "1",
                "action": "move",
                "sparams": {},
                "dparams": {"x": 3, "y": 4, "z": 5},
                "priority": ""
            },
            {
                "uid": "2",
                "action": "takeoff",
                "sparams": {},
                "dparams": {},
                "priority": "1"
            }
        ],
        "condition": "",
        "trigger": {
            "type": "timeDelay",
            "details": {
                "time": "10s"
            }
        },
        "nextId": 6
    }]
}


if __name__ == "__main__":
    print(type(taskData))
    response = requests.post('http://172.21.2.6:8000/task/', json=taskData)
    print(response.content)